package com.atguigu.yygh.msm.service.Impl;

import com.atguigu.yygh.msm.service.MsmService;
import com.atguigu.yygh.msm.utils.SDKTestSendTemplateSMS;
import com.atguigu.yygh.vo.msm.MsmVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.HashMap;
import java.util.concurrent.TimeUnit;

/**
 * ClassName: MsmServiceImpl
 * Package: com.atguigu.yygh.msm.service.Impl
 *
 * @Date: 2021/8/28 9:52
 * @author: 浪漫
 * @Description:
 */
@Service
@Slf4j
public class MsmServiceImpl implements MsmService {

    @Autowired
    private RedisTemplate redisTemplate;

    // mq发送短信
    @Override
    public boolean send(MsmVo msmVo) {
        if(!StringUtils.isEmpty(msmVo.getPhone())) {
            HashMap<String, Object> result = SDKTestSendTemplateSMS.sms(msmVo.getPhone());
            if("000000".equals(result.get("statusCode"))){
        String code = (String) result.get("code");
        // 存入redis  设置过期时间为五分钟
        redisTemplate.opsForValue().set(msmVo.getPhone(),code,5, TimeUnit.MINUTES);
                log.info("mq发送短信=====" + result);
                return  true;
            }
        }
        //System.out.println("发送短信成功！==" + msmVo);
        return true;

    }
}
